﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Gift.DAL.crm;
using Gift.Model.crm;
using Gift.Model.crm.eNum;

namespace WebSite.crm.company
{
    public partial class companyMoney : BaseCrm
    {
        readonly t_DALCompany theCompany = new t_DALCompany();

        string ParamentType
        {
            get
            {
                return Request.QueryString["type"];
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
     
                    base.ValidateLoginRule(eRule.InOutMoney);
     
                try
                {
                    if (Request.QueryString["type"] == "out")
                    {
                        this.lblType.Text = "出账";
                    }
                    else
                    {
                        this.lblType.Text = "入账";
                    }
                    t_Company oCompany;
                    oCompany = theCompany.GetModel(int.Parse(Request.QueryString["id"]));
                    if (base.CompanyId == oCompany.Id.ToString())
                    {
                        this.txtMoney.Enabled = false;
                        this.txtRemark.Enabled = false;
                        this.btnSaveRefresh.Enabled = false;
                    }
                    this.lblCompanyName.Text = oCompany.Name;
                }
                catch
                {
                    ExtAspNet.Alert.Show("非法操作！");

                }
            }
        }


        protected void btnSaveRefresh_Click(object sender, EventArgs e)
        {
            string sSQL = "insert into t_CompanyMoney(CompanyId,InMoney,OutMoney,OperateTime,AdminId,Remark) "
                        + " values({0},{1},{2},'{3}',{4},'{5}')";
            float inMoney = 0;
            float outMoney = 0;

            if (Request.QueryString["type"] == "out")
            {
                outMoney = float.Parse(this.txtMoney.Text);

            }
            else
            {
                inMoney = float.Parse(this.txtMoney.Text);
            }

            SQLAccess.DoSql(string.Format(sSQL, Request.QueryString["id"], inMoney, outMoney, DateTime.Now.ToString(), base.LoginAdminId, this.txtRemark.Text.Trim()));
            ExtAspNet.Alert.Show("保存成功！");
            ExtAspNet.PageContext.RegisterStartupScript(ExtAspNet.ActiveWindow.GetHidePostBackReference());
        }

      
    }
}